﻿using System;

namespace AgFractal.Fractals
{
    public class Burko1 : AbstractFractal
    {
        public Burko1()
        {
            ID = new Guid("F3CA7041-31FE-4e65-A3B0-AECFC394FC9F");
            Name = "Burko1";
            Description = "I (Ladislav Burkovsky) created this fractal by accident.";
            R1 = 0; I1 = 6; R2 = 27; I2 = -6;
            
            var cParam = new FractalParameter { Name = "c", ComplexValue = c };
            cParam.PropertyChanged += (s, e) => c = cParam.ComplexValue;
            parameter.Add(cParam);
        }

        private Complex c = new Complex(0, 0);
        protected override short Calculate(double r, double i, short MaxIteration)
        {
            short j;
            Complex z = c;
            Complex p = new Complex(r,i);
            
            for (j = 0; j < MaxIteration; j++)
            {
                z = ((z.Sqr() + p - 1) / (2 * z - p + 2)).Sqr();
                if (z.Abs2() > 100 && (z - 1).Abs() > 0.00005) break;                
            }
            return j;
        }
    }
}